import { IFeidaoAiMobile } from '@dfeidao/atom-mobile/interfaces';
import set from '@dfeidao/atom-mobile/local/set';
import nodejs from '@dfeidao/atom-mobile/msg/nodejs';
import get_param from '@dfeidao/atom-mobile/nav/get-param';
import render from '@dfeidao/atom-mobile/render/render';
import whoami from '../atom/whoami_getparams';
export default async function a001(fd: IFeidaoAiMobile) {
	const users = await whoami(fd) as { params: { teacher_name: string; productid: string; } };
	const productid = users.params.productid;
	const teacher_name = users.params.teacher_name;
	// const asd = fd.data.params;
	const leave_num = await get_param(fd, 'leave_num');
	// const leave_num = 'XQ000132';// todo
	set(fd, 'leave_num', leave_num);
	set(fd, 'productid', productid);
	set(fd, 'teacher_name', teacher_name);
	const res = await nodejs<{ data: Array<{ parent_number: string; student_no: string; student_name: string; parent_name: string }> }>('app-approval-details/s001', { productid, leave_num });
	// console.log(res);
	if (res.data.length > 0) {
		// 学生编号
		const student_no = res.data[0].student_no;
		// 学生姓名
		const student_name = res.data[0].student_name;
		// 家长姓名
		const parent_name = res.data[0].parent_name;
		// 家长编号
		const parent_number = res.data[0].parent_number;
		set(fd, 'student_no', student_no);
		set(fd, 'student_name', student_name);
		set(fd, 'parent_name', parent_name);
		set(fd, 'parent_number', parent_number);

		const res1 = await nodejs<{ data: Array<{}>; phone: { phone: string }; }>('app-approval-details/s004', { parent_number, productid });
		const phone = res1.phone.phone;
		set(fd, 'phone', phone);
	}
	render(fd, { data: res.data, teacher_name, btns: '1' });
}
